package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.response.MaintainListResponse;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 * Created by luo_guangwen on 2017/10/10.
 */

public class GetMaintainListRequest extends Request<MaintainListResponse> {
    private long last_id;
    public static final int size = 20;
    private String keyword = "";

    public GetMaintainListRequest(long last_id, String keyword, Response.Listener<MaintainListResponse> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/maintain_record_list"), listener);
        this.last_id = last_id;
        this.keyword = keyword;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());
        addParam("access_token", CacheManager.getAccessToken());
        addParam("last_id", last_id + "");
        addParam("size", size + "");
        addParam("keyword", keyword);
        return super.getParams();
    }

    @Override
    protected MaintainListResponse parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<MaintainListResponse>() {
        }.getType());
    }

}

